package fat
{

import com.fit4as.fit.*;
import com.fit4as.util.io.StringWriter;

public class DocumentParseFixture extends ColumnFixture
{
    public var HTML : String;
    public var Note : String;  // non-functional

    public function Output() : String {
        return GenerateOutput(Parse.createParse(HTML));
    }

    public function Structure() : String {
        return dumpTables(Parse.createParse(HTML));
    }

    private function GenerateOutput(parse : Parse) : String {
        var result : StringWriter = new StringWriter();
        parse.print(result);
        return result.getContent();
    }

    private function dumpTables(table : Parse) : String {
        var result : String = "";
        var separator : String = "";
        while (table != null) {
            result += separator;
            result += dumpRows(table.parts);
            separator = "\n----\n";
            table = table.more;
        }
        return result;
    }

    private function dumpRows(row : Parse) : String {
        var result : String = "";
        var separator : String = "";
        while (row != null) {
            result += separator;
            result += dumpCells(row.parts);
            separator = "\n";
            row = row.more;
        }
        return result;
    }

    private function dumpCells(cell : Parse) : String {
        var result : String = "";
        var separator : String = "";
        while (cell != null) {
            result += separator;
            result += "[" + cell.body + "]";
            separator = " ";
            cell = cell.more;
        }
        return result;
    }
}
}